#ifndef _OSTRING_H_
#define _OSTRING_H_
#include "Object.h"
#include <QString>

class OString : public Object
{
public:
    OString(){ _real = ""; }

    OString(const OString & other) { _real = other._real; }
    OString(const QString & other){_real = other;}
    OString(const QChar *unicode, int size) { _real = QString(unicode, size); }
    explicit OString(const QChar *unicode) { _real = QString(unicode); }
    OString(QChar c) {_real = QString(c); }
    OString(int size, QChar c) {_real = QString(size, c); }
    OString(const QLatin1String &latin1) { _real = QString(latin1); }
    OString(const char *ch) { _real = QString(ch); }
    OString &operator=(const OString &other) { _real = other._real; return *this; }

    //operator QString *() const { return &this->_real; }
    operator QString &() { return _real; }
    operator const QString &() const { return _real; }

    QString mid(int position, int n = -1) const {return _real.mid(position, n);}
    int length() const {return _real.length(); }
    int size() const {return _real.size(); }

    virtual ~OString(){}

    bool operator==(const QString &s) const { return _real == s; }
    bool operator<(const QString &s) const { return _real < s; }
    inline bool operator>(const QString &s) const { return s < _real; }
    inline bool operator!=(const QString &s) const { return !operator==(s); }
    inline bool operator<=(const QString &s) const { return !operator>(s); }
    inline bool operator>=(const QString &s) const { return !operator<(s); }

    bool operator==(const OString &s) const {return _real == s._real;}
    bool operator<(const OString &s) const {return _real < s._real;}
    inline bool operator>(const OString &s) const { return s._real < _real; }
    inline bool operator!=(const OString &s) const { return !operator==(s); }
    inline bool operator<=(const OString &s) const { return !operator>(s); }
    inline bool operator>=(const OString &s) const { return !operator<(s); }

    OString &operator+=(QChar c){ _real += c; return *this; }
    inline OString &operator+=(QChar::SpecialCharacter c) { return append(QChar(c)); }
    inline OString &operator+=(const OString &s) { return append(s); }
    inline OString &operator+=(const QStringRef &s) { return append(s); }
    inline OString &operator+=(const QLatin1String &s) { return append(s); }

    OString &append(QChar c) { _real.append(c); return *this; }
    OString &append(const QString &s) { _real.append(s); return *this; }
    OString &append(const QStringRef &s) { _real.append(s); return *this; }
    OString &append(const QLatin1String &s) { _real.append(s); return *this; }

    virtual QString type(){ return "OString"; }
    QString str() const { return _real;}
    QString trim() {return _real.trimmed();}
    OString toString(){ return *this;}
    void setLength(int length) {_real.resize(length);}
    void clear() {_real.clear();}
    void setCharAt(int pos, const QChar chr) {_real = _real.replace(pos, 1, chr);}

    static QString fromAscii(const char *str, int size = -1) { return OString(QString::fromAscii(str, size)); }
private:
    QString _real;
};

#endif
